//
//  SearchPersonTableViewCell.m
//  TestApplication
//
//  Created by Hanlingyu on 16/9/21.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "SearchPersonTableViewCell.h"
#import "SearchPersonContent.h"
#import "SearchPersonFeel.h"
#import "UIImageView+WebCache.h"
@interface SearchPersonTableViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *headerImage;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIButton *followButton;


@end

@implementation SearchPersonTableViewCell

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        
        
    }
    return self;
}

- (void)setSearchKey:(NSString *)searchKey {
    _searchKey = searchKey;
    _nameLabel.attributedText = [self makeAutriblute:_searchKey totalString:_searchPerson.uname];


}


- (void)setSearchPerson:(SearchPersonContent *)searchPerson {
    _searchPerson = searchPerson;
//    _nameLabel.text = [NSString stringWithFormat:@"%@", _searchPerson.uname];
    [_headerImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://qn.zheli.io/%@", _searchPerson.avatar]]];

    
    
}

// 去除请求下来的数据中多余的字符串并给关键字加高亮
- (NSMutableAttributedString *)makeAutriblute :(NSString *)string totalString:(NSString *)totalString {
    
    NSString *title = [NSMutableString stringWithFormat:@"%@",string];
    // 找到搜索关键字在字符串中的range;
    NSRange range = [totalString rangeOfString: title];
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:totalString];
    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.259 green:1.000 blue:0.751 alpha:1.000] range:range];
    [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15 weight:3] range:range];
    
    return attributedString;
}



- (void)layoutSubviews {
    [super layoutSubviews];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
